#include <bits/stdc++.h>
// 2025/01/21
// tag: 
// Author: Zhang Muen
using namespace std;

int parents[501], n, m, k, f;
unordered_set<int> um[251];


class UF
{
public:
    int cnt;

    UF(int n)
    {
        cnt = n;
        for (int i = 1; i <= n; i++)
            parents[i] = i;
    };

    int find(int i)
    {
        if (parents[i] != i)
            return find(parents[i]);
        return parents[i];
    }

    void un(int j, int i)
    {
        int rj = find(j);
        parents[i] = rj;
    }
};

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> k >> f;
    UF uf(n);
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        um[a].insert(b);
    }
    for (int i = 0; i < f; i++){
        int a, b;
        cin >> a >> b;
        uf.un(a, b);
    }
    for (int i = 1; i <= n; i++){
        for (auto x: um[i])
            um[uf.find(i)].insert(x);
    }
    int ans = INT_MAX;
    for (int i = 1; i <= n; i++)
        ans = min(ans, (int)um[uf.find(i)].size());
    cout << min(ans + k, n) << endl;
    return 0;
}